//
//  HMTabBar.swift
//  sinaweibo
//
//  Created by Reality on 2017/6/29.
//  Copyright © 2017年 wangjing. All rights reserved.
//

import UIKit

class HMTabBar: UITabBar {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    ///设置视图
    private func setupUI(){
        addSubview(composeButton)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let w = frame.size.width * 0.2
        
        var index : CGFloat = 0
        
        for view in subviews {
            if view.isKind(of: NSClassFromString("UITabBarButton")!) {
                
                view.frame.size.width = w
                view.frame.origin.x = w * index
                
                index += 1
                
                if index == 2 {
                    index += 1
                }
            }
        }
        
        composeButton.center.x = frame.size.width * 0.5
        composeButton.center.y = frame.size.height * 0.5
    }
    
    private lazy var composeButton:UIButton = {
        
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), for: UIControlState.highlighted)
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button"), for: UIControlState.normal)
        
        btn.setImage(UIImage(named:"tabbar_compose_icon_add_highlighted"), for: UIControlState.highlighted)
                btn.setImage(UIImage(named:"tabbar_compose_icon_add"), for: UIControlState.normal)
        
        btn.sizeToFit()
        
        return btn
    }()
}
